#include "H264DecSDK.h"

class H264DecodeFilter : public CTransformFilter
{
public:

    static CUnknown * WINAPI CreateInstance(LPUNKNOWN punk, HRESULT *phr);

    // Reveals IContrast & ISpecifyPropertyPages
    STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);

    DECLARE_IUNKNOWN;

    HRESULT Transform(IMediaSample *pIn, IMediaSample *pOut);
    HRESULT CheckInputType(const CMediaType *mtIn);
    HRESULT CheckTransform(const CMediaType *mtIn,const CMediaType *mtOut);
    HRESULT GetMediaType(int iPosition, CMediaType *pMediaType);
    HRESULT DecideBufferSize(IMemAllocator *pAlloc,
                             ALLOCATOR_PROPERTIES *pProperties);

	int GetBitrate();
	int GetActualFps() 
	{ 	
		if (timeGetTime() - _lastBitrateCountTime > 2 * BITRATE_COUNT_INTERVAL)
			return 0;
		else
			return _lastActualFps;
	}

    // Constructor
    H264DecodeFilter(TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr);
	~H264DecodeFilter();

	void PausePlayback();
	void ContinuePlayback();
	void StepForward();

	bool IsConnected();
	bool IsPaused() { return _isPaused;}

	STDMETHODIMP Stop();

private:
	H264DECSESSION m_session;
	AM_MEDIA_TYPE m_intype, m_outtype;
	int _width, _height;
	bool _isPaused;
	bool _willStepForward;

	DWORD _lastBitrateCountTime;
	DWORD _lastBitrate;
	UINT _totalBit;
	DWORD _lastActualFps;
	DWORD _totalFrame;

}; // H264DecodeFilter

